/*
 * Brown, Gregory; Negron, Luz; Noecker, David; Spangler, Michael
 * Pennsylvania State University
 * 2011
 *
 * Copyright (c) 2011, Brown Negron Noecker Spangler
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 * - Neither the name of Pennsylvania State University nor the names of its
 * contributors may be used to endorse or promote products derived from this
 * software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * Person Class for IST 411 project
 * This class provides the basic structure for a person.
 *
 * Will be implemented by Student as well as Faculty.
 */

package courseScheduler;

/**
 *
 * @author David Noecker
 */
public abstract class Person {
    // Person's Name
    private String fName;
    private String lName;
    private char mInitial;

    //Person's Address
    private String addressOne;
    private String addressTwo;
    private String city;
    private String state;
    private String zip;

    //Person's Contact Information
    private String phone;
    private String mobile;
    private String email;

    //Person's D.O.B. Information
    private int age;
    private date dob;

    //Constructors
    /**
     * Person constructor that takes in first and last name as well as the D.O.B
     * only.
     * @param newFName first name.
     * @param newLName last name.
     * @param newDOB date of birth.
     */
    public Person(String newFName, String newLName, date newDOB){
        fName = newFName;
        lName = newLName;
        dob = new date(newDOB);
    }

    public Person(){
    }

    /**
     * Person constructor that takes in an already existing person.
     * @param newPerson existing person.
     */
    public Person(Person newPerson){
        fName = newPerson.getFName();
        lName = newPerson.getLName();
        mInitial = newPerson.getMInitial();
        addressOne = newPerson.getAddressOne();
        addressTwo = newPerson.getAddressTwo();
        city = newPerson.getCity();
        state = newPerson.getState();
        zip = newPerson.getZip();
        phone = newPerson.getPhone();
        mobile = newPerson.getMobile();
        email = newPerson.getEmail();
        age = newPerson.getAge();
        dob = newPerson.getDOB();
    }

    //Sets and Gets
    //<editor-fold>

    /**
     * This class method is used to set the first name of the person.
     * @param newFName new value for the first name string.
     */
    public void setFName(String newFName){
        fName = newFName;
    }

    /**
     * This class method is used to access the first name of the person.
     * @return First name.
     */
    public String getFName(){
        return fName;
    }

    /**
     * This class method is used to set the last name of the person.
     * @param newLName new value for the last name string.
     */
    public void setLName(String newLName){
        lName = newLName;
    }

    /**
     * This class method is used to access the last name of the person.
     * @return Last name.
     */
    public String getLName(){
        return lName;
    }

    /**
     * This class method is used to set the middle initial of the person.
     * @param newMI new value for the middle initial character.
     */
    public void setMInitial(char newMI){
        mInitial = newMI;
    }

    /**
     * This class method is used to access the middle initial of the person
     * @return Middle initial.
     */
    public char getMInitial(){
        return mInitial;
    }

    /**
     * This class method is used to set the first address line for the person.
     * @param newLine new value for the first address line.
     */
    public void setAddressOne(String newLine){
        addressOne = newLine;
    }

    /**
     * This class method is used to access the first address line for the person.
     * @return Address line one.
     */
    public String getAddressOne(){
        return addressOne;
    }

    /**
     * This class method is used to set the second address line for the person.
     * @param newLine new value for the second address line.
     */
    public void setAddressTwo(String newLine){
        addressTwo = newLine;
    }


    /**
     * This class method is used to access the second address line for the person.
     * @return Address line two.
     */
    public String getAddressTwo(){
        return addressTwo;
    }

    /**
     * This class method is used to set the city for the person.
     * @param newCity new value for the city.
     */
    public void setCity(String newCity){
        city = newCity;
    }

    /**
     * This class method is used to access the city of the person.
     * @return City.
     */
    public String getCity(){
        return city;
    }

    /**
     * This class method is used to set the state of the person.
     * @param newState the new value of state.
     */
    public void setState(String newState){
        state = newState;
    }

    /**
     * This class method is used to access the state of the person.
     * @return State.
     */
    public String getState(){
        return state;
    }

    /**
     * This class method is used to set the zip-code of the person.
     * @param newZip new value of zip-code.
     */
    public void setZip(String newZip){
        zip = newZip;
    }

    /**
     * This class method is used to access the zip-code of the person.
     * @return Zip-code.
     */
    public String getZip(){
        return zip;
    }

    /**
     * This class method is used to set the phone number of the person.
     * @param newPhone new value of phone number.
     */
    public void setPhone(String newPhone){
        phone = newPhone;
    }

    /**
     * This class method is used to access the phone number of the person.
     * @return Phone number.
     */
    public String getPhone(){
        return phone;
    }

    /**
     * This class method is used to set the mobile number of the person.
     * @param newMobile new value of the mobile number.
     */
    public void setMobile(String newMobile){
        mobile = newMobile;
    }

    /**
     * This class method is used to access the mobile number of the person.
     * @return Mobile number.
     */
    public String getMobile(){
        return mobile;
    }

    /**
     * This class method is used to set the email of the person.
     * @param newEmail new value for email.
     */
    public void setEmail(String newEmail){
        email = newEmail;
    }

    /**
     * This class method is used to access the email of the person.
     * @return
     */
    public String getEmail(){
        return email;
    }

    /**
     * This class method is used to set the age of the person.
     * @param newAge new value for age.
     */
    public void setAge(int newAge){
        age = newAge;
    }

    /**
     * This class method is used to access the age of the person.
     * @return Age.
     */
    public int getAge(){
        return age;
    }

    /**
     * This class method is used to set the D.O.B. of the person
     * @param newDOB new value for date of birth.
     */
    public void setDOB(date newDOB){
        dob = newDOB;
    }

    /**
     * This class method is used to access the D.O.B. of the person.
     * @return Date of birth.
     */
    public date getDOB(){
        return dob;
    }
    //</editor-fold>

    public static String getType(java.sql.Connection newConn, String user, String password) throws java.sql.SQLException, SchedulerException{
        java.sql.Statement stmnt = newConn.createStatement();
        java.sql.ResultSet rs = stmnt.executeQuery("SELECT type FROM person WHERE user_name LIKE \"" + user + "\" AND password LIKE password(\"" + password + "\");");
        System.out.println("SELECT type FROM person WHERE user_name LIKE \"" + user + "\" AND password LIKE password(\"" + password + "\");");
        if(rs.first()){
            String type = rs.getString(1);
            rs.last();
            if (rs.getRow() > 1){
                throw new SchedulerException("Multiple Users Found");
            }
            return type;
        }
        else{
            throw new SchedulerException("No Users Found");
        }
    }

    public static int getID(java.sql.Connection newConn, String user, String password) throws java.sql.SQLException, SchedulerException {
        java.sql.Statement stmnt = newConn.createStatement();
        System.out.println("id");
        
        java.sql.ResultSet rs = stmnt.executeQuery("SELECT id FROM person WHERE user_name LIKE \"" + user + "\" AND password LIKE password(\"" + password + "\");");
        if(rs.first()){
            int id = rs.getInt(1);
            rs.last();
            if (rs.getRow() > 1){
                throw new SchedulerException("Multiple Users Found");
            }
            return id;
        }
        else{
            throw new SchedulerException("No Users Found");
        }
    }

    //To String Method

    /**
     * This is the method that returns the String value of the person.
     * Right now that value is only the name of the person.
     * Other possible returns are every piece of information delimited by
     * punctuation or tabs.
     * @return String representation of person.
     */
    @Override
    public String toString(){
        return (fName + " " + mInitial + ". " + lName);
    }

}
